package org.yunzhong.commontool.controller;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.yunzhong.commontool.service.HolidayApplyService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Controller
@Api(tags = "根据模板生成文档", description = "生成文档")
@RequestMapping("/template")
public class TemplateController {

    @Autowired
    private HolidayApplyService holidayApplyService;

    @ApiOperation(value = "生成请假申请单")
    @PostMapping(value = "holiday/generate")
    @ResponseBody
    public String customList(@RequestParam("excels") MultipartFile[] excels, @RequestParam("docs") MultipartFile[] docs,
            @RequestParam("date") String date) throws IOException {
        try (var excelInputStream = excels[0].getInputStream();
                var docInputStream = docs[0].getInputStream()) {
            String fullPath = holidayApplyService.generate(excelInputStream, docInputStream, date);
            return fullPath;
        }
    }
}
